#!/bin/bash 
repoUrl=""
allRev=""
output=""

function Usage()
{
	echo 'Usage: fs.get-whatsnew-by-rev.sh -b|--branch your_svn_repo_url -r|--reversion rev1,rev2,rev3 -o|--output your_output_file'
}
function GetSvnLog()
{
	local repoUrl="$1"
	local rev="$2"
	local out="$3"
	local revUserDate=""
	local revLog=""
	# user date
	echo "getting log of $rev"
	revUserDate="`svn.shc log $repoUrl -r $rev  | grep "^r${rev}" 	| awk '{print $1 " " $3 " "  $5}'`"
	revLog="`svn.shc log $repoUrl -r $rev | sed "s/^---*//g" 	| sed "s/^r${rev}.*//" | tr "\n" ";"`"
	if [ "$revUserDate$revLog" != "" ];then 
		echo -e "[===\n${revUserDate}" >> $out
		echo "$revLog" >> $out
		echo -e "===]\n" >>  $out
	fi
}

while [ $# != 0 ]; do
	case $1 in
	-b|--branch)
		repoUrl="$2"
		shift
	;;


	-r|--reversion)
		allRev="$2"
		shift
	;;
	
	-o|--output)
		output="$2"
		shift
	;;

	*)
		Usage
		exit
	;;
	esac
	shift
done

if [ "$repoUrl" == "" ] || [ "$allRev" == "" ]; then
	echo "Missing argument!!!"
	Usage
	exit
fi
if [ "$output" == "" ];then
	output="svnLogByRev.txt"
fi
allRev="`echo "$allRev" | tr ',' ' '`"
for ov in $allRev;do
	realVer="`svn.shc log $repoUrl -r $ov | grep "^r[0-9][0-9]*" | awk '{print $1}' | tr -d "r" | tr "\n" " "`"
		for rv in $realVer;do
			GetSvnLog "$repoUrl" "$rv" "$output"
		done
done
sed -i "s/;;;*/;/g" $output
